﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Eb.StockManagement;

public partial class Modules_StockManagement_StockIssueHistory : System.Web.UI.UserControl
{
    StockManagement stockMgmt = new StockManagement();
    protected void Page_Load(object sender, EventArgs e)
    {

        if (!IsPostBack)
        {
            PopulateProductionWiseBOM();
            PopulateFromSalesIssue();
            PopulateIssueForOthers();
        }

    }

    protected void PopulateProductionWiseBOM()
    {
        DataSet productDS = stockMgmt.GetMaterialBatchHistory();
        grvBatchHistory.DataSource = productDS;
        grvBatchHistory.DataBind();
    }
    protected void PopulateFromSalesIssue()
    {
        DataSet productDS = stockMgmt.IssueFromSales();
        grvForSales.DataSource = productDS;
        grvForSales.DataBind();
    }
    protected void PopulateIssueForOthers()
    {
        DataSet productDS = stockMgmt.GetIssueForOthers();
        grvForOthers.DataSource = productDS;
        grvForOthers.DataBind();

    }
    protected void grvForOthers_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        #region NameSpace
        int lotId = 0;
        DataSet stockDetailsDS = new DataSet();
        #endregion
        try
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                GridView gv = (GridView)e.Row.FindControl("grvProductMovement3");
                string lblLotId = ((Label)e.Row.FindControl("lblID2")).Text;
                if (lblLotId != "")
                    lotId = Convert.ToInt16(lblLotId);
                if (lotId > 0)
                {
                    stockDetailsDS = stockMgmt.GetIssueForOthers(lotId);
                    gv.DataSource = stockDetailsDS;
                    gv.DataBind();
                }
            }
        }
        catch (Exception exp)
        {
            Session["ERRTITLE"] = "Failed to retrive LotId !";
            Session["ERRDET"] = exp.Message;
            Response.Redirect("ErrorPage.aspx");
        }
    }
    
    protected void grvForSales_RowDataBound(object sender, GridViewRowEventArgs e)
    {
         #region NameSpace
        int lotId = 0;
        DataSet stockDetailsDS = new DataSet();
        #endregion
        try
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                GridView gv = (GridView)e.Row.FindControl("grvProductMovement1");
                string lblLotId = ((Label)e.Row.FindControl("lblLotID1")).Text;
                if (lblLotId != "")
                    lotId = Convert.ToInt16(lblLotId);
                if (lotId > 0)
                {
                    stockDetailsDS = stockMgmt.IssueFromSalesByLotID(lotId);
                    gv.DataSource = stockDetailsDS;
                    gv.DataBind();
                }
            }
        }
        catch (Exception exp)
        {
            Session["ERRTITLE"] = "Failed to retrive LotId !";
            Session["ERRDET"] = exp.Message;
            Response.Redirect("ErrorPage.aspx");
        }
    }
    
    protected void grvBatchHistory_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        #region NameSpace
        int lotId = 0;
        DataSet stockDetailsDS = new DataSet();
        #endregion
        try
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                GridView gv = (GridView)e.Row.FindControl("grvProductMovement");
                string lblLotId = ((Label)e.Row.FindControl("lblLotID")).Text;
                if (lblLotId != "")
                    lotId = Convert.ToInt16(lblLotId);
                if (lotId > 0)
                {
                    stockDetailsDS = stockMgmt.GetMaterialHistoryByLotID(lotId);
                    gv.DataSource = stockDetailsDS;
                    gv.DataBind();
                }
            }
        }
        catch (Exception exp)
        {
            Session["ERRTITLE"] = "Failed to retrive purchaseOrderID !";
            Session["ERRDET"] = exp.Message;
            Response.Redirect("ErrorPage.aspx");
        }
    }
}
